package Controllers;

import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JOptionPane;

import Entities.LoginEntity;
import GUI.LoginGUI;

/**
 * The Class MainWindowController.
 * Controller for handling logout event / client closing event in the main window
 */
public class MainWindowController implements Observer{

	
	/* (non-Javadoc)
	 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
	 */
	@Override
	public void update(Observable o, Object arg) {
		String msg = (String) arg.toString();
		if(msg.equals("error"))
			JOptionPane.showMessageDialog(null, "Log out failed");
		else if(msg.equals("#Server:Action succeded"))
				new LoginController(new LoginGUI(),new LoginEntity());
		else if(msg.equals("#OS:Client disconnected."))
			try {
				
				ClientController.observableClient.closeConnection();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		
	}

}
